﻿// =================================================================== 
// 数据访问层(GDIT.DAL)
//====================================================================
// 文件：DSceneryPicInfo.cs
// 项目名称：学院网站
// 创建时间：2012-08-08
// 负责人：ChenZhiGang
//引用DevExpress.Data.Filtering，DevExpress.Xpo程序集
// 程序集介绍：风貌信息数据访问层
// ===================================================================
using GDIT.Model;
using DevExpress.Data.Filtering;
using DevExpress.Xpo;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GDIT.Pattern;
using System.Data;

namespace GDIT.DAL
{
    public class DSceneryPicInfo :ISceneryPicInfo
    {

        private XpoHelper.Test<Mtb_SceneryPicInfo> userOperation = null;

        /// <summary>
        /// 根据输入的类型对风貌进行查询并返回
        /// </summary>
        /// <param name="typeName">类型</param>
        /// <returns></returns>
        public IDataReader SelectSceneryPicInfoByType(string typeName)
        {
            return XpoHelper.SelectID("select sp.OID, Title, PicPath, Alt from dbo.Mtb_SceneryPicInfo as sp join dbo.Mtb_PicType as pt on sp.PicType = pt.OID and pt.TypeName = '"+typeName+"'");
        }

        /// <summary>
        /// 新增加一篇公告
        /// </summary>
        /// <param name="bulletin">需要增加的公告对象</param>
        /// <returns>1：新增成功  0：新增失败</returns>
        public int InsertSceneryPicInfo(Mtb_SceneryPicInfo bulletin)
        {
            return XpoHelper.SaveAdded(bulletin);
        }

        /// <summary>
        /// 删除一篇公告
        /// </summary>
        /// <param name="bulletin">需要删除的公告对象</param>
        /// <returns>1：删除成功  0：删除失败</returns>
        public int DeleteSceneryPicInfo(int id)
        {
            userOperation = new XpoHelper.Test<Mtb_SceneryPicInfo>();
            return userOperation.Delete(id);
        }

        /// <summary>
        /// 更新一篇公告
        /// </summary>
        /// <param name="bulletin">需要更新的公告的对象</param>
        /// <returns>1：更新成功  0：更新失败</returns>
        public int UpdateSceneryPicInfo(Mtb_SceneryPicInfo bulletin)
        {
            userOperation = new XpoHelper.Test<Mtb_SceneryPicInfo>();
            XPCollection xp = userOperation.Operation("OID", bulletin.OID);
            foreach (Mtb_SceneryPicInfo b in xp)
            {
                b.Title = bulletin.Title;
                b.PicPath = bulletin.PicPath;
                b.Alt = bulletin.Alt;
                return XpoHelper.SaveModified(b);
            }
            return 0;
        }
    }
}
